<template>
  <div class="user-center">
    <el-container>
      <el-aside width="240px" class="menu">
        <div class="menu-header">
          <h2>用户中心</h2>
        </div>
        <el-menu
          :default-active="activeIndex"
          class="el-menu-vertical-demo"
          @select="handleSelect"
          router="true"
        >
          <el-menu-item index="/user/profile">
            <el-icon><User /></el-icon>
            <span>个人资料</span>
          </el-menu-item>
          <el-menu-item index="/user/password">
            <el-icon><Lock /></el-icon>
            <span>修改密码</span>
          </el-menu-item>
          <el-menu-item index="/user/message">
            <el-icon><Message /></el-icon>
            <span>我的消息</span>
          </el-menu-item>
          <el-menu-item index="/user/post">
            <el-icon><Document /></el-icon>
            <span>我的帖子</span>
          </el-menu-item>
        </el-menu>
      </el-aside>

      <el-main class="content">

        <transition name="fade" mode="out-in">
          <router-view/>
        </transition>
      </el-main>
    </el-container>
  </div>
</template>

<script setup>
import { onMounted, watch,ref } from 'vue'
import { useRoute } from 'vue-router'

const activeIndex=ref('')

const route = useRoute()

onMounted(()=>{
  activeIndex.value=route.path
})

watch(route,(newVal,oldVal)=>{
  activeIndex.value=newVal.path
})
</script>

<style scoped>
.user-center {
  min-height: 100vh;
  background-color: #f5f7fa;
  padding: 20px;
}

.menu {
  background-color: #ffffff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  margin-right: 20px;
  overflow: hidden;
}

.menu-header {
  padding: 20px;
  text-align: center;
  border-bottom: 1px solid #ebeef5;
}

.menu-header h2 {
  margin: 0;
  color: #303133;
  font-size: 20px;
  font-weight: 600;
}

.el-menu-vertical-demo {
  border-right: none;
}

.el-menu-item {
  height: 56px;
  line-height: 56px;
  margin: 8px 0;
  border-radius: 0 24px 24px 0;
  margin-right: 16px;
}

.el-menu-item:hover {
  background-color: #ecf5ff !important;
  color: #409eff !important;
}

.el-menu-item.is-active {
  background: linear-gradient(90deg, #409eff 0%, #79bbff 100%);
  color: #ffffff !important;
}

.el-menu-item .el-icon {
  margin-right: 12px;
  font-size: 18px;
}

.content {
  background-color: #ffffff;
  border-radius: 12px;
  padding: 30px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  min-height: calc(100vh - 40px);
}

/* 添加过渡动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

/* 响应式布局 */
@media screen and (max-width: 768px) {
  .user-center {
    padding: 10px;
  }
  
  .menu {
    width: 100% !important;
    margin-right: 0;
    margin-bottom: 20px;
  }
  
  .el-container {
    flex-direction: column;
  }
}
</style>
